package com.mingqijia.gassafety.shared.facade;

import com.gap.basic.exception.BizException;
import com.mingqijia.gassafety.shared.constant.Constants;
import com.mingqijia.gassafety.shared.user.UserBackend;
import com.mingqijia.gassafety.shared.utils.ApplicationUtils;

import java.util.Objects;

/**
 * 基类
 * @author Damon S.
 * @version v1.0.1
 * @date 2021年04月13日 18:42
 */
public abstract class BaseFacade {

    protected UserBackend getUserBackend() {
        return ApplicationUtils.getWorkingUser();
    }

    protected String getWorkingSpId() {
        return ApplicationUtils.getWorkingSpId();
    }

    protected String getHeaderSpId() {
        return ApplicationUtils.getHeaderSpId();
    }

    protected String getUserBackendId() {
        return getUserBackend().getUserId();
    }

    protected void validateWorkingSpace4Platform() {
        if (!Objects.equals(Constants.PLATFORM_SP, getHeaderSpId())) {
            throw new BizException("无权限！请在【监控平台】下执行操作");
        }
    }

    protected void validateWorkingSpace4Enterprise() {
        if (Objects.equals(Constants.PLATFORM_SP, getHeaderSpId())) {
            throw new BizException("无权限！请在对应企业下执行操作");
        }
    }
}
